package com.donn.securitycontrolplatform.personinfo.controller;


import com.dahuatech.icc.exception.ClientException;
import com.donn.securitycontrolplatform.common.Result;
import com.donn.securitycontrolplatform.common.entity.dahua.PageDTO;
import com.donn.securitycontrolplatform.expection.BusinessException;
import com.donn.securitycontrolplatform.personinfo.entity.PersonInfo;
import com.donn.securitycontrolplatform.personinfo.service.IPersonInfoService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhenglx
 * @since 2022-06-26
 */
@RestController
@RequestMapping("/scp/api/person-info")
@Tag(name = "PersonInfoController", description = "人员管理")
public class PersonInfoController {

    @Autowired
    IPersonInfoService personInfoService;

    @ApiOperation(value = "新增人员")
    @PostMapping("/add")
    @ResponseBody
    public Result add(@ApiParam PersonInfo personInfo) throws BusinessException, ClientException {
        return personInfoService.add(personInfo);
    }

    @ApiOperation(value = "编辑人员")
    @PostMapping("/update")
    @ResponseBody
    public Result update(@RequestBody PersonInfo personInfoDTO) throws BusinessException, ClientException {
        return personInfoService.updatePerson(personInfoDTO);
    }

    @ApiOperation(value = "删除人员")

    @DeleteMapping("/delete")
    @ResponseBody
    public Result delete(@RequestParam Integer personId) throws BusinessException, ClientException {
        return personInfoService.deletePerson(personId);
    }

    @ApiOperation(value = "分页查询列表")
    @PostMapping("/page")
    @ResponseBody
    public Result page(@RequestBody PageDTO<PersonInfo> page) {
        return personInfoService.getPage(page.page());
    }

}
